<template>
  <div class="result_view_wrapper">
    <el-table
        :data="tableData"
        style="width: 100%">
        <!-- 挂号单号， 服务类型， 时间， 操作人， 点击查看图片报告， 宠物狗ID， -->
        <!-- <el-table-column v-for="(item, index) in ['图片', '挂号单号', '服务类型', '时间', '操作人', '图片报告', '宠物狗ID']" 
          :key="index"
          :label="item"
          width="110">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.date }}</span>
          </template>
        </el-table-column> -->

        <el-table-column 
          label="挂号单号">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span v-clipboard:copy="scope.row.regNo" v-clipboard:success="onCopy" v-clipboard:error="onCopyError" style="margin-left: 10px">GH-{{ scope.row.regNo.substring(0, 6) }}</span>
          </template>
        </el-table-column>

        <el-table-column 
          label="服务类型">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.section.sectionname }}</span>
          </template>
        </el-table-column>
        <el-table-column 
          label="时间">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column 
          label="操作人">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.doctor.realname }}</span>
          </template>
        </el-table-column>
        <el-table-column 
          label="宠物">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.pet.nickname }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-image style="box-shadow: 0 0 0px red;"
            @click="handleEdit(scope.$index, scope.row)"
              :src="url" 
              :preview-src-list="srcList">
            </el-image>
            <el-button
            type="primary"
            size="mini"
            @click="handleEdit(scope.$index, scope.row)" :disabled="!dis(scope.row)" >查看</el-button>
            <!-- <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
  </div>
</template>

<script>
import {myGet} from '../utils/api'
  export default {
    data() {
      return {
        tableData: [{
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }], 
        url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
        srcList: [
          'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
          'https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg'
        ]
      }
    },
    mounted(){
      myGet('/reg/all', null).then(res => {
        var myres = res.data.res
        console.debug(myres)
        this.tableData = myres
      }).catch(err => {

      })
    },
    methods: {
      onCopyError(){
        this.$message({showClose: true, message: '复制失败', type: 'error'})
      },
      onCopy(e){
        this.$message({showClose: true, message: '复制成功', type: 'success'})
      },
      dis(row){
        var reportList = row.reportList
        if(reportList == null || reportList.length == 0){
          return false;
        }else{
          return true;
        }
      },
      handleEdit(index, row) {
        console.log(index, row);
        this.srcList = []
        var reportList = row.reportList
        if(reportList == null || reportList.length == 0){
          this.$message({showClose: true, message: '没有报告'})
          return
        }
        reportList.forEach(e => {
          this.srcList.push(e.url)
        });
        console.debug("asfsdf")
      },
      handleDelete(index, row) {
        console.log(index, row);
      }
    }
  }
</script>

<style>
.result_view_wrapper .el-image__error, .el-image__inner, .el-image__placeholder{
  opacity: 0;
}
</style>


<style scoped>
.el-image{
  width: 60px;
  height: 27px;
  position: absolute;
  right: 35%;
  
}
.el-table{
  position: relative;
}
</style>